package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{sid},#{gid})")
    void addSetmealAndCheckGroupIds(@Param("sid") int sid, @Param("gid") Integer gid);

    @Select("SELECT name,age,sex,remark,img  from t_setmeal WHERE id = #{sid}")
    SetmealVO findSetmealById(@Param("sid") int sid);

    @Select("SELECT\n" +
            "\ttc.ID,tc.`NAME`,tc.REMARK\n" +
            "FROM\n" +
            "\tt_setmeal_checkgroup tsc,\n" +
            "\tt_checkgroup tc\n" +
            "WHERE\n" +
            "\ttc.ID=tsc.CHECKGROUP_ID\n" +
            "\tAND tsc.SETMEAL_ID=#{id}")
    List<CheckGroupVO> findCheckGroupListBySetmealId(@Param("id") int id);

    @Select("SELECT t.`NAME` FROM t_checkitem t, t_checkgroup_checkitem tcc WHERE t.ID=tcc.CHECKITEM_ID AND tcc.CHECKGROUP_ID=#{id}")
    List<CheckItem> findCheckItemByGroupId(@Param("id") Integer id);
}
